﻿using UnityEngine;
using UnityEngine.Playables;

namespace Pvp.Timeline
{
    public abstract class BaseRolePlayableAsset<T> : PlayableAsset where T : BaseRolePlayableBehaviour, new()
    {
        public override sealed Playable CreatePlayable(PlayableGraph graph, GameObject owner)
        {
            if (owner.GetComponent<FightUnitEntity>() == null)
                throw new System.Exception("BaseRolePlayableAsset Exception");
            var playable = ScriptPlayable<T>.Create(graph);
            var behaviour = playable.GetBehaviour();
            behaviour.entity = owner.GetComponent<FightUnitEntity>();

            OnBehaviourInit(behaviour);
           
            return playable;
        }

        protected abstract void OnBehaviourInit(T behaviour);
    }
}

